
/**
\file
Definition of the nmn::logger class.
\author Sean Tromans
*/

#ifndef	NMN_TEMPLATE_LOGGER_HPP
#define	NMN_TEMPLATE_LOGGER_HPP

#include <needs_more_ninja/template/create_string.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/noncopyable.hpp>
#include <exception>

namespace nmn
{

	/** Exception thrown when the provided output file for a logger cannot be opened. */
	class cannot_open_file : public std::exception
	{
	public:
		cannot_open_file( std::string const & file )
			:	std::exception( nmn::create_string( "nmn::cannot_open_file: %1%", file ).c_str( ) )
		{}
	};

	/**
	Simple, thread safe logging class.
	\author Sean Tromans
	*/
	class logger : private boost::noncopyable
	{
		//
		//	Public Member Functions
		//
		public:

			/**
			Constructor.
			@param filename The destination log file.
			\author Sean Tromans
			*/
			inline logger( std::string const & filename );

			/**
			Deconstructor.
			\author Sean Tromans
			*/
			inline ~logger( );

			/**
			Outputs a string to the log file.
			@param message The message to output to the log.
			\author Sean Tromans
			*/
			template< typename char_t >
			void operator( )( char_t const * const message );

			/**
			Outputs a string to the log file.
			@param message The message to output to the log.
			\author Sean Tromans
			*/
			template< typename char_t, typename traits_t, typename allocator_t >
			void operator( )( std::basic_string< char_t, traits_t, allocator_t > const & message );

		//
		//	Private Member Variables
		//
		private:

			boost::mutex	m_mutex;
			std::string		m_filename;
	};

}

#include <needs_more_ninja/template/log/logger.inl>

#endif	//NMN_TEMPLATE_LOGGER_HPP
